﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace JHStock.UserForm
{
    public partial class FormSelect : Form
    {
        public FormSelect()
        {
            InitializeComponent();
        }
        private void FormSelect_Load(object sender, EventArgs e)
        {
            buttonMain.PerformClick();
        }
        private void buttonMain_Click(object sender, EventArgs e)
        {
            if (checkJHConfig("main"))
                ShowMainForm(ref _fmain, _jhconfigmain);
        }
        private void buttonTest_Click(object sender, EventArgs e)
        {
            if (checkJHConfig("test"))
                ShowMainForm(ref _ftest, _jhconfigtest);
        }
        private void ShowMainForm(ref Form1 f,  JHConfig jhconfig)
        {
            if (f == null)
            {
                this.Hide();
                f = new Form1(jhconfig);
                f.ShowDialog();
                this.Close();
            }
        }
        private bool checkJHConfig(string actiontype)
        {
            try
            {
                if (actiontype == "main")
                {
                    _jhconfigmain = new JHConfig("jsconfig.ini");
                    return _jhconfigmain.CheckReady();
                }
                else if (actiontype == "test")
                {
                    _jhconfigtest = new JHConfig("jsconfig_debug.ini");
                    return _jhconfigtest.CheckReady();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("配置文件时出现错误： 原因 "+ e.Message);
            }
            return false;
        }

        private Form1 _fmain;
        private Form1 _ftest;   
        private JHConfig _jhconfigmain;
        private JHConfig _jhconfigtest;

    }
}
